use file_sys::{
    block_cache_dev::BlockCacheDevice,
    block_dev::BlockDevice, 
    bitmap::Bitmap, 
    file_disk::FileDisk,
    BLOCK_SIZE,
};

fn get_device() -> Box<BlockCacheDevice> {
    Box::new(BlockCacheDevice::new(Box::new(FileDisk::new("./disk/image").unwrap())))
}

#[test]
fn test_bitmap() {
    let mut device = get_device();
    device.write_block(1, &[0x0u8; BLOCK_SIZE]);
    device.write_block(2, &[0x0u8; BLOCK_SIZE]);

    let mut bitmap = Bitmap::new(1, 2);

    for i in 0..(4096 * 2) {
        assert_eq!(bitmap.alloc(&mut device), Some(i));
    }

    assert_eq!(bitmap.alloc(&mut device), None);
    assert_eq!(bitmap.alloc(&mut device), None);
    assert_eq!(bitmap.alloc(&mut device), None);

}
